import { setRedirectUri } from './auth'
// 生成一个从0到max（不含）的随机整数
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}

console.log(window.baseConfig)

// 环境
export const env = process.env.NODE_ENV;
console.log(`当前环境：${env}`);

// 请求域名
export const baseURL = {
  development: '/api',
  production: window.baseConfig.baseURL,
}[env]

// 资源前缀
export const basAssetsUrl = {
  development: window.baseConfig.basAssetsUrl,
  production: window.baseConfig.basAssetsUrl,
}[env];

// 登陆页面
export const clientId = window.baseConfig.clientId;
export const responseType = window.baseConfig.responseType;
export const grantType = window.baseConfig.grantType;
export const state = getRandomInt(40);
export const redirectUri = `${window.location.origin}/login`;
export const homeUrl = `${window.location.origin}/home`;

// 登录页面
export const baseLoginUrl = {
  development: window.baseConfig.baseLoginUrl,
  production: window.baseConfig.baseLoginUrl,
}[env];

// 登录页面
export const LoginUrl = `${baseLoginUrl}?client_id=${clientId}&response_type=${responseType}&state=${state}&redirect_uri=${redirectUri}`

// 跳转到登录
export const toLogin = () => {
  setRedirectUri(window.location.href);
  window.location.href = LoginUrl;
}

// 页脚配置
export const footerOutLink = window.baseConfig.footerOutLink

// 总平台首页
export const platformHomepage = window.baseConfig.platformHomepage

// 是否显示静态页面
export const isStatic = window.baseConfig.isStatic